package com.example.mobile2032021606168xmy0407homework;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private Button btnMainReset;
    private TextView tvMainContent1;
    private RadioGroup radGupMainText;
    private RadioButton radBtnMainOpt1a;
    private RadioButton radBtnMainOpt1b;
    private RadioButton radBtnMainOpt1c;
    private RadioButton radBtnMainOpt1d;
    private TextView tvMainContent2;
    private RadioGroup radGupMainNumber;
    private RadioButton radBtnMainOpt2a;
    private RadioButton radBtnMainOpt2b;
    private RadioButton radBtnMainOpt2c;
    private RadioButton radBtnMainOpt2d;
    private TextView tvMainContent3;
    private RadioGroup radGupMainTextView;
    private RadioButton radBtnMain3a;
    private RadioButton radBtnMain3b;
    private RadioButton radBtnMain3c;
    private RadioButton radBtnMain3d;
    private TextView tvMainContent4;
    private RadioGroup radGupMainDirection;
    private RadioButton radBtnMain4a;
    private RadioButton radBtnMain4b;
    private RadioButton radBtnMain4c;
    private RadioButton radBtnMain4d;
    private Button btnMainSub;
    private TextView tvMainGrade;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radGupMainText.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton=findViewById(checkedId);
                Log.i("TAG", radioButton.getText().toString());
            }
        });
        radGupMainNumber.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton=findViewById(checkedId);
                Log.i("RaddioButton",radioButton.getText().toString());
            }
        });
        radGupMainTextView.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton=findViewById(checkedId);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        radGupMainDirection.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton=findViewById(checkedId);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });


        btnMainReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RadioButton radioButton=findViewById(radGupMainText.getCheckedRadioButtonId());
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        btnMainReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RadioButton radioButton=findViewById(radGupMainNumber.getCheckedRadioButtonId());
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        btnMainReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RadioButton radioButton=findViewById(radGupMainTextView.getCheckedRadioButtonId());
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        btnMainReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RadioButton radioButton=findViewById(radGupMainDirection.getCheckedRadioButtonId());
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });


        btnMainSub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RadioButton radioButton=findViewById(radGupMainText.getCheckedRadioButtonId());
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        btnMainSub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RadioButton radioButton=findViewById(radGupMainNumber.getCheckedRadioButtonId());
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        btnMainSub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RadioButton radioButton=findViewById(radGupMainTextView.getCheckedRadioButtonId());
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        btnMainSub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String msg=null;
                int selectID=radGupMainDirection.getCheckedRadioButtonId();
                int  DirectionID=radGupMainDirection.getCheckedRadioButtonId();
               // int selectID = radGupMainDirection.getCheckedRadioButtonId();
                if (selectID != -1) {
                    RadioButton radioButton = findViewById(selectID);
                    Log.i("RadioButton", radioButton.getText().toString());
                }else {
                    Log.i("RadioButton","未选择");
                }
            }
        });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        btnMainReset = (Button) findViewById(R.id.btn_main_reset);
        tvMainContent1 = (TextView) findViewById(R.id.tv_main_content1);
        radGupMainText = (RadioGroup) findViewById(R.id.radGup_main_text);
        radBtnMainOpt1a = (RadioButton) findViewById(R.id.radBtn_main_opt1a);
        radBtnMainOpt1b = (RadioButton) findViewById(R.id.radBtn_main_opt1b);
        radBtnMainOpt1c = (RadioButton) findViewById(R.id.radBtn_main_opt1c);
        radBtnMainOpt1d = (RadioButton) findViewById(R.id.radBtn_main_opt1d);
        tvMainContent2 = (TextView) findViewById(R.id.tv_main_content2);
        radGupMainNumber = (RadioGroup) findViewById(R.id.radGup_main_number);
        radBtnMainOpt2a = (RadioButton) findViewById(R.id.radBtn_main_opt2a);
        radBtnMainOpt2b = (RadioButton) findViewById(R.id.radBtn_main_opt2b);
        radBtnMainOpt2c = (RadioButton) findViewById(R.id.radBtn_main_opt2c);
        radBtnMainOpt2d = (RadioButton) findViewById(R.id.radBtn_main_opt2d);
        tvMainContent3 = (TextView) findViewById(R.id.tv_main_content3);
        radGupMainTextView = (RadioGroup) findViewById(R.id.radGup_main_TextView);
        radBtnMain3a = (RadioButton) findViewById(R.id.radBtn_main_3a);
        radBtnMain3b = (RadioButton) findViewById(R.id.radBtn_main_3b);
        radBtnMain3c = (RadioButton) findViewById(R.id.radBtn_main_3c);
        radBtnMain3d = (RadioButton) findViewById(R.id.radBtn_main_3d);
        tvMainContent4 = (TextView) findViewById(R.id.tv_main_content4);
        radGupMainDirection = (RadioGroup) findViewById(R.id.radGup_main_direction);
        radBtnMain4a = (RadioButton) findViewById(R.id.radBtn_main_4a);
        radBtnMain4b = (RadioButton) findViewById(R.id.radBtn_main_4b);
        radBtnMain4c = (RadioButton) findViewById(R.id.radBtn_main_4c);
        radBtnMain4d = (RadioButton) findViewById(R.id.radBtn_main_4d);
        btnMainSub = (Button) findViewById(R.id.btn_main_sub);
        tvMainGrade = (TextView) findViewById(R.id.tv_main_grade);
    }
}